package com.umanji.security.domain;

import java.util.UUID;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;

import com.umanji.generic.entity.UUIDEntity;

@Entity
@Table(name="acl_permission")
public class AclPermission extends UUIDEntity<AclPermission> {

    // @ManyToOne
    // @JoinColumn(name="acl_object_identity_id", insertable=false, updatable=false)
    // @ManyToOne
    // @JoinColumn(name="acl_object_identity_fk")
    // @ManyToOne
    @ManyToOne (cascade = {CascadeType.REFRESH, CascadeType.MERGE})
    @JoinColumn(name="FK_ACLOBJECTIDENTITY_ID")
    private AclObjectIdentity aclObjectIdentity;

    @Column(name = "recipient", unique = true, nullable = false)
    @Size(min = 1, max = 70)
    @Pattern(regexp = ".+", message = "recipient must not be empty!")
    private String recipient;

    private int mask; // INTEGER NOT NULL,

	protected AclPermission() {
		// TODO Auto-generated constructor stub
	}

    public AclPermission(AclObjectIdentity aclObjectIdentity, String recipient, int mask) {
        this.aclObjectIdentity = aclObjectIdentity;
        this.recipient = recipient;
        this.mask = mask;
    }

    public AclPermission(String recipient, int mask) {
        this.recipient = recipient;
        this.mask = mask;
    }

	public String getRecipient() {
		return recipient;
	}

	public void setRecipient(String recipient) {
		this.recipient = recipient;
	}

	public int getMask() {
		return mask;
	}

	public void setMask(int mask) {
		this.mask = mask;
	}

	public AclObjectIdentity getAclObjectIdentity() {
		return aclObjectIdentity;
	}

	public void setAclObjectIdentity(AclObjectIdentity aclObjectIdentity) {
		this.aclObjectIdentity = aclObjectIdentity;
	}

}
